package com.example.demo.quartz.scheduler;


import com.example.demo.quartz.job.CallMyGirlFriendsJob;
import com.example.demo.quartz.trigger.SimpleGetTrigger;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/*
 *
 *   @Author:max
 *   @Date: 2024/4/12-04-12-10:42
 *   任务调度器工具
 */
public class SchedulerUtil {
    public static void addJob() throws SchedulerException {
        // 创建一个标准的调度器工厂
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        // 获取调度器实例
        Scheduler scheduler = schedulerFactory.getScheduler();
        // JobDetail作业实例 JobBuilder 是哪个马楼被控制
        JobDetail jobDetail = JobBuilder.newJob(CallMyGirlFriendsJob.class)
                .withIdentity("schedulerName", "schedulerGroup")
                .build();// 设置作业名称和组
        // 创建一个触发器
        Trigger trigger = SimpleGetTrigger.createTrigger();
        // 添加作业和触发器 绑定    把马楼和上下班时间绑定
        scheduler.scheduleJob(jobDetail, trigger);
        // 启动调度器
        scheduler.start();
    }
}
